select *,count(IDPHOTO) as nb from (select photo.* from photo ) as tb group by IDPHOTO Order by nb DESC